home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / amiga / modelers / chmsthtc / chmsthtc.lzh / Chemesthetics / Source / Source.LZH / convm3d / convm3d.c next >
Encoding:
C/C++ Source or Header  |  1991-09-12  |  4.1 KB  |  172 lines

  1. /* $Revision Header *** Header built automatically - do not edit! ***********
  2.  *
  3.  *    (C) Copyright 1991 by Metalworx
  4.  *
  5.  *    Name .....: convm3d.c
  6.  *    Created ..: Fri 13-Sep-91 13:45
  7.  *    Revision .: 0
  8.  *
  9.  *    Date        Author        Comment
  10.  *    =========    ========    ====================
  11.  *    07-Jul-91    Mtwx        Created this file!
  12.  *
  13.  * $Revision Header ********************************************************/
  14.  #define REVISION 0
  15.  
  16. /***************************************************************************
  17. * convm3d.c: Programm zum Konvertieren von Molec3D-Files in Chemesthetics- *
  18. *         Datenfiles                            *
  19. ***************************************************************************/
  20.  
  21. /* ------------------------------- includes ----------------------------- */
  22.  
  23. #include <ctype.h>
  24. #include <math.h>
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include <exec/types.h>
  29.  
  30. /* ------------------------------- defines ------------------------------ */
  31.  
  32. #define MAXATOMS 500
  33.  
  34. /* ------------------------------- global references -------------------- */
  35.  
  36. char *Atom[MAXATOMS],DAtom[106][3];
  37. int X[MAXATOMS],Y[MAXATOMS],Z[MAXATOMS];
  38. double Radius[106];
  39.  
  40. /* ------------------------------- external references ------------------ */
  41.  
  42. extern char ProgId[],Version[],Date[];      /* from rev.c */
  43. extern int Revision;
  44.  
  45. /* ------------------------------- prototypes --------------------------- */
  46.  
  47. int main(int,char**);
  48. void zeile_verarbeiten(char*,int);
  49. void usage(void);
  50.  
  51. /* ------------------------------- routines ----------------------------- */
  52.  
  53. int main(int argc, char **argv)
  54. {
  55.   int i,j,hradius=50,numatoms=0,numdatoms=0;
  56.   BOOL found=FALSE;
  57.   char zeile[82];
  58.   FILE *edatei, *adatei, *ddatei;
  59.  
  60.   printf("\n%s %s/%d - %s,  (C) 1991 Metalworx\n",ProgId,Version,Revision,
  61.      Date);
  62.   if(argc<3 || argc>4)
  63.   {
  64.     usage();
  65.     exit(1);
  66.   }
  67.   if(argc==4)
  68.     hradius=atoi(argv[3]);
  69.   edatei=fopen(argv[1],"r");
  70.   if(!edatei)
  71.   {
  72.     perror(argv[1]);
  73.     exit(1);
  74.   }
  75.   adatei=fopen(argv[2],"w");
  76.   if(!adatei)
  77.   {
  78.     perror(argv[2]);
  79.     exit(1);
  80.   }
  81.   ddatei=fopen("convm3d.dta","r");
  82.   if(!ddatei)
  83.   {
  84.     perror("Datafile 'convm3d.dta' not found");
  85.     exit(1);
  86.   }
  87.   printf("reading");
  88.   while(!feof(ddatei))
  89.   {
  90.     fgets(zeile,10,ddatei);
  91.     zeile[strlen(zeile)-1]='\0';  /* delete \n */
  92.     strcpy(DAtom[numdatoms],zeile);
  93.     fgets(zeile,10,ddatei);
  94.     Radius[numdatoms]=atof(zeile);
  95.     numdatoms++;
  96.     printf(".");
  97.   }
  98.   fclose(ddatei);
  99.   printf("\nprocessing");
  100.   strcpy(zeile,"");
  101.   do
  102.   {
  103.     fgets(zeile,80,edatei);
  104.     zeile_verarbeiten(zeile,numatoms);
  105.     numatoms++;
  106.     printf(".");
  107.   } while(zeile[0]!='\n');
  108.   numatoms--;        /* do not take empty line ! */
  109.  
  110. /* save output file */
  111.   printf("\nwriting");
  112.   fprintf(adatei,"%d\n",numatoms);    /* save number of atoms */
  113.   for(i=0;i<numatoms;i++)
  114.   {
  115.     printf(".");
  116.     /* save atom and its coordinates */
  117.     fprintf(adatei,"%s\n%d\n%d\n%d\n",Atom[i],X[i], Y[i],Z[i]);
  118.     for(j=0;j<numdatoms;j++)
  119.     {
  120.       if(stricmp(Atom[i],DAtom[j])==NULL)
  121.       {
  122.     fprintf(adatei,"%d\n",(int)((Radius[j]/Radius[0])*(double)hradius));
  123.     found=TRUE;
  124.       }
  125.     }
  126.     if(!found)
  127.       printf("Atom %s not included in convm3d.dta\n",Atom[i]);
  128.     found=FALSE;
  129.   }
  130.   fprintf(adatei,"1.0\n"); /* magnification factor */
  131.   fprintf(adatei,"0\n0\n0\n"); /* molecul turns X-Y-Z */
  132.   fprintf(adatei,"10000.0\n-200000.0\n10000.0\n"); /* light vector */
  133.   fprintf(adatei,"10\n"); /* reflection */
  134.   fclose(edatei);
  135.   fclose(adatei);
  136.   printf("\nfinished!\n");
  137.   exit(0);
  138. }
  139.  
  140. void zeile_verarbeiten(char *zeile,int count)
  141. {
  142.   register int i=-1,j=0;
  143.   char Name[3];
  144.   double x,y,z;
  145.  
  146.   while(isspace(zeile[++i]));
  147.   while(isalpha(zeile[i]))
  148.     Name[j++]=zeile[i++];
  149.   Name[j]='\0';
  150.   Atom[count]=malloc(3);
  151.   strcpy(Atom[count],Name);
  152.  
  153.   i+=2;     /* set to white space */
  154.   while(isspace(zeile[++i]));
  155.   x=atof(&zeile[i]);
  156.   while(!isspace(zeile[i++]));
  157.   while(isspace(zeile[++i]));
  158.   y=atof(&zeile[i]);
  159.   while(!isspace(zeile[i++]));
  160.   while(isspace(zeile[++i]));
  161.   z=atof(&zeile[i]);
  162.  
  163.   X[count]=(int)(x*100.0);
  164.   Y[count]=(int)(y*100.0);
  165.   Z[count]=(int)(z*100.0);
  166. }
  167.  
  168. void usage(void)
  169. {
  170.   puts("usage: convm3d <infile> <outfile> [H-radius]");
  171. }
  172.